
<template>
	<div class="components-container">
        <!-- 新增/修改 -->
        <sweet-modal ref="dialog" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">灵堂名称</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ashesData.ICDNAME" placeholder="请选择灵堂" style="width:100%">
                                <el-option v-for="item in linNames" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                   <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDREGNAME"></el-input>
                        </div>
                    </div>
                </div>
                  <div class="layui-form-item">
                    <div class="layui-inline">
                      <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDREGAGE"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ashesData.ICDREGSEX" filterable>
                            <el-option v-for="item in sexType" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue">
                            </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">接运地点</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDADDRESS"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">接运日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDDATE"></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null" type="date" v-date v-model="ashesData.ICDTIME" format='HH:mm'></el-time-picker>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDSTARTDATE"></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="ashesData.ICDSTARTTIME" format='HH:mm'></el-time-picker>
                        </div>
                    </div>
                     <div class="layui-inline">
                        <label class="layui-form-label">结束日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDENDDATE"></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="ashesData.ICDENDTIME" format='HH:mm'></el-time-picker>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开厅人员</label>
                    <div class="layui-input-inline">
                            <!-- courtStaff -->
                        <el-select v-model="ashesData.ICDLINMAN" placeholder="请选择开庭人员">
                            <el-option v-for="item in courtStaff" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submit">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">灵堂名称</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ashesData.ICDNAME" placeholder="请选择灵堂" disabled>
                                <el-option v-for="item in linNames" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                   <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDREGNAME" readonly></el-input>
                        </div>
                    </div>
                </div>
                  <div class="layui-form-item">
                    <div class="layui-inline">
                      <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDREGAGE" readonly></el-input>
                        </div>
                    </div>
                     <div class="layui-inline">
                      <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDREGSEXDESC" readonly></el-input>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">接运地点</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ICDADDRESS" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">接运日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDDATE" readonly></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null"  v-date v-model="ashesData.ICDTIME" format='HH:mm' readonly></el-time-picker>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDSTARTDATE" readonly></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="ashesData.ICDSTARTTIME" format='HH:mm' readonly></el-time-picker>
                        </div>
                    </div>
                     <div class="layui-inline">
                        <label class="layui-form-label">结束日期</label>
                        <div class="layui-input-inline chooseTime">
                          <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="ashesData.ICDENDDATE" readonly></el-date-picker>
                          <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="ashesData.ICDENDTIME" format='HH:mm' readonly></el-time-picker>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                     <div class="layui-inline">
                        <label class="layui-form-label">开厅人员</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ashesData.ICDLINMAN" placeholder="请选择开庭人员" disabled>
                                <el-option v-for="item in courtStaff" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
            </div>
        </sweet-modal>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "ashesManage",
  props: {
    orderType: {
      type: String,
      default() {
        return ADD;
      }
    }
  },
  data() {
    return {
      title: null,
      ashesData: {
        ICDTYPE: '2',
        ICDSTATUSS: null
      },

      xMax: 100,
      yMax: 100,

      usetype: [],
      TMXSTATUSS: [],
      sexType: [],

      TMXSTATUSA: null,

      ashesTypes: [],
      areaTypes: [],
      courtStaff: [],
      linNames: [],
    };
  },
  watch: {
    "ashesData.ASSASAID": function(val) {
      if (
        this.ashesData.ASSASAID !== null &&
        this.ashesData.ASSASAID !== undefined &&
        this.ashesData.ASSASAID !== ""
      ) {
        var data = {
          ASAID: this.ashesData.ASSASAID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashesarea.Detail,
          res => {
            this.xMax = res.data.content.ASAXCOUNT;
            this.yMax = res.data.content.ASAYCOUNT;
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      }
    }
  },
  methods: {
    //获取灵堂
    getlins() {
        apiBase.DoService({},
            apiBase.getApiAdress().MourningUse.QueryMourning,
            res => {
                let linTypeData = res.data.content,
                    legendsLinData = linTypeData.map(item => ({
                        label: item.LINNAME,
                        value: item.LINID
                    }));
                this.linNames = legendsLinData;
            }
        );
    },
    // 获取开庭人员
    getcourtStaff() {
        apiBase.DoService({},
            apiBase.getApiAdress().Staff.QueryOpeningstaff,
            res => {
                let linTypeData = res.data.content,
                    legendsLinData = linTypeData.map(item => ({
                        label: item.STANAME,
                        value: item.STAID
                    }));
                this.courtStaff = legendsLinData;
            }
        );
    },
    //获取逝者性别
     getSexType() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetSex, res => {
        this.sexType = res.data.content;
      });
    },
    //获取销售状态
    gettmxstatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Refrigerateddata.GetICDSTATUS,
        res => {
          this.TMXSTATUSS = res.data.content;
        }
      );
    },
    //功能操作
    open(order,id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "守灵室使用新增";
          this.initSelectData();//初始化下拉框数据
          this.$refs.dialog.open();
          break;
        case MODIFY:
          this.title = "守灵室使用修改";
          this.dataInfo(id);
           this.initSelectData();//初始化下拉框数据
          this.$refs.dialog.open();
          break;
        case DELETE:
          this.dataDelete(id);
          break;
        case INFO:
          this.title = "守灵室使用详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },
    //取消
    cancel() {
      this.$refs.dialog.close();
      this.$refs.dialogInfo.close();
    },
    //冷藏新增
    dataAdd() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      console.log(data)
      if(this.ashesData.ICDDATE){
        data.ICDDATE =  formatDate(this.ashesData.ICDDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDTIME){
        data.ICDTIME =  formatDate(this.ashesData.ICDTIME, "hhmmss");
      }
      if(this.ashesData.ICDSTARTDATE){
        data.ICDSTARTDATE =  formatDate(this.ashesData.ICDSTARTDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDSTARTTIME){
        data.ICDSTARTTIME =  formatDate(this.ashesData.ICDSTARTTIME, "hhmmss");
      }
      if(this.ashesData.ICDENDDATE){
        data.ICDENDDATE =  formatDate(this.ashesData.ICDENDDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDENDTIME){
        data.ICDENDTIME =  formatDate(this.ashesData.ICDENDTIME, "hhmmss");
      }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Refrigerateddata.Create,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //墓穴修改
    dataModify() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      if(this.ashesData.ICDDATE){
        data.ICDDATE =  formatDate(this.ashesData.ICDDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDTIME){
        data.ICDTIME =  formatDate(this.ashesData.ICDTIME, "hhmmss");
      }
      if(this.ashesData.ICDSTARTDATE){
        data.ICDSTARTDATE =  formatDate(this.ashesData.ICDSTARTDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDSTARTTIME){
        data.ICDSTARTTIME =  formatDate(this.ashesData.ICDSTARTTIME, "hhmmss");
      }
      if(this.ashesData.ICDENDDATE){
        data.ICDENDDATE =  formatDate(this.ashesData.ICDENDDATE, "yyyyMMdd");
      }
      if(this.ashesData.ICDENDTIME){
        data.ICDENDTIME =  formatDate(this.ashesData.ICDENDTIME, "hhmmss");
      }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Refrigerateddata.Modify,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //墓穴删除
    dataDelete(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          ICDID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Refrigerateddata.Delete,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //冷藏详情
    dataInfo(id) {
      console.log(5858);
      console.log(id);
      var data = {
        ICDID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Refrigerateddata.Detail,
        res => {
          this.ashesData = res.data.content;
          this.ashesData.ICDID = id;
          this.ashesData.ICDTIME = timeStringToDate(//详情中的到馆时间
            res.data.content.ICDTIME
          );
          this.ashesData.ICDSTARTTIME = timeStringToDate(//详情中的到馆时间
            res.data.content.ICDSTARTTIME
          );
          this.ashesData.ICDENDTIME = timeStringToDate(//详情中的到馆时间
            res.data.content.ICDENDTIME
          );
          this.ashesData.ICDSTATUSS = this.tmxstatusa(res.data.content.ICDSTATUS);
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    tmxstatusa(val){
        switch(val){
          case "A":
            return "可售";
          break;
          case "B":
            return "预售";
          break;
          case "C":
            return "已售";
          break;
          case "D":
            return "已使用";
          break;
          case "E":
            return "已迁出";
          break;
          case "F":
            return "禁售";
          break;
          default:
        }
    },
    //数据重置
    dataRepeat() {
      this.ashesData = {
        ICDTYPE: '2',
      };
    },
    //初始化下拉框数据
    initSelectData() {
      this.getSexType();
      this.gettmxstatus();
    },
    refreshData() {
      this.$emit("refreshData");
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    }
  },
  components: {
    sweetModal
  },
  mounted() {},
  created() {
      this.getlins();
      this.getcourtStaff();
  }
};
</script>